package org.example.basic.functionclass;



import org.example.basic.entity.UserEntity;
import org.example.basic.entity.UserEntityList;
import org.example.basic.util.FunctionUtil;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Copyright (C), 2022, szw
 * FileName: SupplierFunction
 *
 * @author songyafei
 * Date:     2022/1/21 15:16
 * Description: Supplier 的案例
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
public class SupplierFunction {

    public static void main(String[] args) {
        List<UserEntity> item = UserEntityList.getItem();
        Optional<UserEntity> supplier = FunctionUtil.supplier(
                () -> item.stream()
                        .filter(m -> m.getAge() > 18)
                        .sorted(Comparator.comparing(UserEntity::getCreatedDate).reversed())
                        .collect(Collectors.toList())
                        .stream().findFirst());
        System.out.println(supplier.get());
    }
}
